/**
* Created by yyr on 2018/3/15
*已设立基金编辑选项卡基金详细》基金账户信息
*/
<template>
    <div>
        <div class="ca-p-22 ca-box ca-m-t-15" v-if="!isAccountEdit">
            <el-row>
                <el-col :span="12" class="ca-title">
                    <h3>基金账户信息</h3>
                    <div class="clear"></div>
                </el-col>
                <el-col :span='12' class="ca-align-right">
                    <el-button type="text" @click="fundAccountEdit()" :disabled="!isAuthBasicEdit" class="ca-edit-btn el-icon-edit">编辑</el-button>
                </el-col>
            </el-row>
            <table class="ca-table" cellpadding="0" cellspacing="0">
                <tr>
                    <th width="16%" style="background:#ececec"></th>
                    <th width="28%">开户行名称</th>
                    <th width="28%">户名</th>
                    <th width="28%">账号</th>
                </tr>
                <tr v-for="(row,index) in accountList" :key="index">
                    <td style="background:#ececec">{{row.type| getNameById('account')}}</td>
                    <td>{{row.nameOfBank}}</td>
                    <td>{{row.name}}</td>
                    <td>{{row.accountNumber}}</td>
                </tr>
            </table>
        </div>
        <csFundAccountEdit
            v-if="isAccountEdit"
            @isEdit="isEdit"
            :accountList="accountList"
            @saveFundAccount="saveFundAccount"
        ></csFundAccountEdit>
    </div>
</template>

<script type="text/ecmascript-6">
    import {api} from '../api';
    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
    import {isNoAuth} from '__service/utils';
    export default {
        data() {
            return {
                isAuthBasicEdit: isNoAuth('已投资基金-基金详情-编辑'),
                itemId: this.$route.params.fundId,
                isAccountEdit: false,//选项卡[0]账户
                accountList: [],
            }
        },
        props: {
        },
        created() {
            this.getAccountList()
        },
        mounted() {
        },
        methods: {
            getAccountList() {
                apiHttp(api.GET_ACCOUNT_LIST,{id: this.itemId}).then( ret=>{
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.accountList = ret.data;
                    }
                })
            },
            saveFundAccount(accountList) {
                //先保存在关闭
                apiHttp(api.CHANGE_ACCOUNT,accountList).then( ret=>{
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.$message({
                            message: '修改成功',
                            type: 'success',
                            center: true
                        });
                        this.isAccountEdit = false;
                        this.getAccountList();
                        this.$emit('addRedDot',0)
                    }
                })
            },
            fundAccountEdit() {
                this.isAccountEdit = true;
            },
            isEdit(val) {
                this.isAccountEdit = val;
                this.getAccountList();
            },
        },
        components: {
            'csFundAccountEdit': require('./edit'), //选项卡基本信息》账户信息 edit
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>

</style>
